home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SpriteEngine / SpriteHanders.c < prev    next >
C/C++ Source or Header  |  1995-03-10  |  1KB  |  61 lines

  1. #include "SpriteTools.h"
  2.  
  3. // SpriteTools.h includes SpriteHandlers.h
  4.  
  5.  
  6. /*** Custom handlers - application dependent ***
  7.  
  8. Edit this as necessary. It should always include the following three routines:
  9.  
  10. MoveSprite: move the sprite
  11.  
  12. HitSprite: handle collisions between two sprites
  13.  
  14. InitSprites: Load all faces and create initial sprites
  15.  
  16. ***/
  17.  
  18.  
  19.  
  20. GrafPtr    firstFace, secondFace, thirdFace;
  21.  
  22.  
  23. void MoveSprite(SpritePtr theSprite)
  24. {
  25.     theSprite->position.h += theSprite->speed.h;
  26.     theSprite->position.v += theSprite->speed.v;
  27.     KeepOnScreen(theSprite);
  28.  
  29. } /*MoveSprite*/
  30.  
  31. void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
  32. {
  33. } /*HitSprite*/
  34.  
  35.  
  36. void InitSprites()
  37. {
  38.     SpritePtr    theSprite;
  39.  
  40. /*Load all pictures*/
  41.     firstFace = LoadFaceFromCicn(128);            /*cicn resource #128.*/
  42.     secondFace = LoadFaceFromCicn(129);            /*cicn resource #129.*/
  43.     thirdFace = LoadFaceFromCicn(130);            /*cicn resource #130.*/
  44.  
  45. /*Create sprites*/
  46.     theSprite = NewSprite();
  47.     theSprite->face = firstFace;
  48.     SetPt(&theSprite->position, 100, 100);
  49.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  50.  
  51.     theSprite = NewSprite();
  52.     theSprite->face = secondFace;
  53.     SetPt(&theSprite->position, 50, 50);
  54.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  55.  
  56.     theSprite = NewSprite();
  57.     theSprite->face = thirdFace;
  58.     SetPt(&theSprite->position, 150, 150);
  59.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  60. } /*InitSprites*/
  61.